package de.tsystems.jsfdict.api.impl;

import de.tsystems.jsfdict.model.Language;
import de.tsystems.jsfdict.model.Word;

import javax.inject.Named;
import java.util.List;

@Named("languageDao")
class LanguageDaoImpl extends AbstractDao<Language> implements LanguageDao {
    @Override
    public Class<Language> getEntityClass() {
        return Language.class;
    }

    @Override
    public Language findByName(String languageName) {
        return (Language) getCurrentSession()
            .createQuery("from Language language where name=:name")
            .setParameter("name", languageName)
            .uniqueResult();
    }

    @Override
    public List<Word> getWords(Language language) {
        return getCurrentSession()
                .createQuery("from Word word where language=:language")
                .setParameter("language", language)
                .list();
    }
}
